﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_PrintPrice1 : System.Web.UI.Page
{
    int accountid;
    int projectid;
    string usercode;
    string accountname;
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql;
        string count = "";
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            accountid = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["accountid"]));
            projectid = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["projectid"]));
            usercode = SysFun.IsSQL(Request.QueryString["usercode"]);
            accountname = SysFun.IsSQL(Request.QueryString["accountname"]);
            Db db = new Db();
            System.Data.IDataReader dr;
            sql = "Select count(*) as cun from project_bid where accountid=" + accountid + " and projectid=" + projectid + " And CheckStatus=1";
            dr = db.DataReader(sql);
            while (dr.Read())
            {
                count = dr["cun"].ToString();
            }
            dr.Close();
            dr.Dispose();
            db.Close();
            showGridView();
        }
    }

    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidprice";
        dbPage.Key = "Bidid";
        dbPage.Where = strConditions;                        //
        dbPage.SelectField = "Bidid,ProductCode,BidTableName,BidTableType,BidTableOutlookc,ProductName,Outlookc,Pack,Medicinemodel,goodsname,FactoryUserCode,factor,scname,smprice,spprice,QualityLevels,TBRNAME,TBUserCode";                             //可以不设，默认为“*”
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 3000;//Request.QueryString["PS"]);
        dbPage.OrderBy = "ProductName,Outlookc,Medicinemodel,Bidid";
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        
        
        
        //this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
        string _strSql = "update ProjectCompanyAttribution set memo4=1 where accountid=" + accountid + "  and  projectid =" + projectid;
        db.Command(_strSql);
        dbPage.Db.Close();
        db.Close();
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        // 添加头信息，为"文件下载/另存为"对话框指定默认文件名 
        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(accountid.ToString()) + ".xls");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        this.GridView1.RenderControl(oHtmlTextWriter);

        // 把文件流发送到客户端 
        Response.Write(oStringWriter.ToString());
        // 停止页面的执行
        Response.Write("<script>window.close();</script>"); 
        Response.End();


    }

    public string fctConditions()
    {
        string strtemp = "";
        strtemp = "accountid_tb=" + accountid + " and projectid=" + projectid + " and CheckStatus='1' And ProductCode is not null and";
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }
    //打印报价


    public override void VerifyRenderingInServerForm(Control control)
    {
        //OverRide　为了使导出成Excel可行！
    }
}
